﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using Portal.Ef.Repository;


namespace Portal.Ef.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            var entity = new Entities();
            var pruduct = new ProductRepository();
            var stopwatch = new Stopwatch();

            stopwatch.Start(); //  开始监视代码运行时间
            //for (int i = 0; i < 100000; i++)
            //{
            //    entity.AddToTbAction(new TbAction { CoActionId = Guid.NewGuid().ToString(), CoName = i.ToString(CultureInfo.InvariantCulture) });
            //}
            //entity.SaveChanges();
            stopwatch.Stop(); //  停止监视
            TimeSpan timespan = stopwatch.Elapsed;
            Console.WriteLine(string.Format("毫秒:{0}", timespan.TotalMilliseconds));

            var list = entity.TbAction.Where(o => true);
            stopwatch.Start();
            //foreach (var item in list)
            //{
            //    Console.WriteLine(item.CoActionId+"_______"+item.CoName);
            //}
            foreach (var tbAction in list)
            {
                entity.DeleteObject(tbAction);
            }
            entity.SaveChanges();

            stopwatch.Stop(); //  停止监视
            timespan = stopwatch.Elapsed;
            Console.WriteLine(string.Format("毫秒:{0}", timespan.TotalMilliseconds));
            Console.WriteLine(entity.TbAction.Count(o => true) + "");


            stopwatch.Start();
            //foreach (var item in list)
            //{
            //    Console.WriteLine(item.CoActionId+"_______"+item.CoName);
            //}

            for (int i = 0; i < 10; i++)
            {
                pruduct.Add(new Product { Id = Guid.NewGuid().ToString(), Name = i.ToString(CultureInfo.InvariantCulture) });
            }
            pruduct.Save();
            Console.ReadLine();
            var listproduct = pruduct.Get().Where(o => true);

            foreach (var item in listproduct)
            {
                Console.WriteLine(item.Id + "_______" + item.Name);
            }

            Console.WriteLine(pruduct.Get().Count(o => true) + "");
            Console.ReadLine();
            foreach (var tbAction in pruduct.Get().Take(10))
            {
                pruduct.Delete(tbAction);
            }
            pruduct.Save();
            Console.ReadLine();
            listproduct = pruduct.Get().Where(o => true);
            foreach (var item in listproduct)
            {
                Console.WriteLine(item.Id + "_______" + item.Name);
            }
            stopwatch.Stop(); //  停止监视
            timespan = stopwatch.Elapsed;
            Console.WriteLine(string.Format("毫秒:{0}", timespan.TotalMilliseconds));
            Console.WriteLine(pruduct.Get().Count(o => true) + "");
            Console.ReadLine();

        }
    }
}
